
function AudioUtils() {
    this.arr = [{}, {}];

    this.index = 0;
    this.mergeMusicMap = this.arr[this.index];

    this.__swap = function() {
        this.index ++;
        this.index %= this.arr.length;
        this.mergeMusicMap = this.arr[this.index];
    }

    this.playMergeMusic = function(combo = 1) {
        if (combo == 1) {
            this.__swap();
        }

        var player = this.mergeMusicMap[combo];
        // var player = null;
        if (player == null) {
            var fileId = combo >= 8 ? 8 : combo;
            const audioFile = "res/audio/" + fileId + ".mp3";
            player = new Audio(audioFile);
            this.mergeMusicMap[combo] = player;
        }
        console.log("playMergeMusic:" + combo);
        player.pause();
        player.play();
    }
}

var gAudioUtils = new AudioUtils();